<?php

if ($_F->compareToken($data4, $SESSION_WRITE)) {
// 현재글의 uid
    $result_uid = $r->return_result_by_array($TABLE, "", "max(uid) as maxuid,max(ord_num) as maxord");
// 글이 하나도 없으면 1


    print_r($result_uid);

    if (!$result_uid['maxuid']) {
        $ord_num = 1;
        $uid = 1;
        $r->db->query("ALTER TABLE $TABLE AUTO_INCREMENT = 1");
    } else {
        $uid = $result_uid['maxuid'] + 1;
        $ord_num = $result_uid['maxord'] + 1;
    }



    $field = "board_id,uid,board_table,ord_num,board_subject,board_content,user_nick,remove_password,reg_date,ip_addr";
    $value = "'','$uid','$category','$ord_num','$data3','$content','$data1',password('$data2'),now(),'{$_SERVER['REMOTE_ADDR']}'";
    if (!$r->db->query("insert into $TABLE ($field) values ($value)")) {
        throw new Exception("<br>file : " . __FILE__ . "<br>line : " . __LINE__ . "<br>sql insert 에러");
    }
    $r->db->close();
} else {
    throw new Exception("<br>file : " . __FILE__ . "<br>token 불일치");
}